package com.bakerj.infinitecards.transformer;

import com.bakerj.infinitecards.AnimationTransformer;

import ohos.agp.components.Component;

import java.math.BigDecimal;

/**
 * DefaultCommonTransformer
 *
 * @author BakerJ
 * @since : 2021.5.24
 */
public class DefaultCommonTransformer implements AnimationTransformer {
    @Override
    public void transformAnimation(Component view, float fraction,
                                    int cardWidth, int cardHeight, int fromPosition, int toPosition) {
        int positionCount = fromPosition - toPosition;
        BigDecimal num1 = new BigDecimal(0.8f);
        BigDecimal num2 = new BigDecimal(0.1f);
        BigDecimal num3 = new BigDecimal(fromPosition);
        BigDecimal num4 = new BigDecimal(fraction);
        BigDecimal num5 = new BigDecimal(positionCount);
        BigDecimal add = num1.subtract(num2.multiply(num3)).add(num2.multiply(num4).multiply(num5));
        //float scale = (0.8f - 0.1f * fromPosition) + (0.1f * fraction * positionCount);
        view.setScaleX(add.floatValue());
        view.setScaleY(add.floatValue());
        BigDecimal num6 = new BigDecimal(-cardHeight);
        BigDecimal num7 = new BigDecimal(cardWidth);
        BigDecimal num8 = new BigDecimal(0.02);
        BigDecimal num9 = new BigDecimal(0.5);
        view.setTranslationY(num6.multiply(num1.subtract(add)).
                multiply(num9).
                subtract(num7.multiply(num8.multiply(num3).subtract(num8.multiply(num4).multiply(num5)))).floatValue());
    }

    @Override
    public void transformInterpolatedAnimation(Component view, float fraction,
                                                int cardWidth, int cardHeight, int fromPosition, int toPosition) {
    }
}
